package com.doyens.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.doyens.reggie.commons.BaseContext;
import com.doyens.reggie.domain.AddressBook;
import com.doyens.reggie.mapper.AddressBookMapper;
import com.doyens.reggie.service.AddressBookService;
import org.springframework.stereotype.Service;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    @Override
    public void setDefault(AddressBook addressBook) { //addressBook===id
        // 1.修改当前用户的所有地址为0
        AddressBook ad = new AddressBook();
        ad.setIsDefault(0);
        this.update(ad,new LambdaQueryWrapper<AddressBook>().eq(AddressBook::getUserId, BaseContext.getCurrentId()));

        //2.将指定的那一条数据的地址指定为1
        ad.setIsDefault(1);
        this.update(ad,new LambdaQueryWrapper<AddressBook>().eq(AddressBook::getId,addressBook.getId()));
    }
}
